package com.planet.events;

import java.util.ArrayList;

import com.planet.classes.Event;
import com.planet.classes.Events;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class StartActivity extends Activity {	
	private Button button_map;
	private Button button_events;
	private Button button_favs;
	private Bundle _bundle;
	private ViewFlipper hl_flipper;
	private ArrayList<View> views;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        _bundle = getIntent().getExtras();
        
        button_map = (Button)this.findViewById(R.id.button_map);
        button_events = (Button)this.findViewById(R.id.button_events);
        button_favs = (Button)this.findViewById(R.id.button_favs);
        hl_flipper = (ViewFlipper)this.findViewById(R.id.hl_flipper);
        
        LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        
        Events events = (Events)_bundle.getSerializable("Events");
        ArrayList<Event> eventList = events.getEventList();
        for(int i=0; i < eventList.size(); i++){
        	Event event = eventList.get(i);
        	if(event.is_isHighlight()){
        		View v = inflater.inflate(R.layout.hightlights_view, null);
        		TextView title = (TextView)v.findViewById(R.id.hl_title);        		
        		title.setText(event.get_title());
        		TextView date = (TextView)v.findViewById(R.id.hl_date);        		
        		date.setText(event.get_date());
        		hl_flipper.addView(v);
        	}
        }
        
        hl_flipper.setOnClickListener(new View.OnClickListener() {			
			public void onClick(View v) {
				hl_flipper.showNext();				
			}
		});
        
        button_map.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				final CharSequence[] map_items = {"Gasometer","((szene))"};
				final AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
				builder.setTitle("Veranstaltungsort:");
				builder.setItems(map_items, new DialogInterface.OnClickListener() {					
					public void onClick(DialogInterface dialog, int item) {
						if(item == 0){
							Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
							Uri.parse("geo:0,0?q=Bank Austria Halle, Guglgasse 8, 1110 Wien"));
							startActivity(intent);
						}else if(item == 1){
							Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
							Uri.parse("geo:0,0?q=Szene Wien, Hauffgasse 26, 1110 Wien"));
							startActivity(intent);
						}
					}								
				});
				AlertDialog alert = builder.show();	
			}
		});
        
        button_events.setOnClickListener(new View.OnClickListener() {			
			public void onClick(View v) {
				Bundle bundle = new Bundle();
	            bundle.putSerializable("Events", _bundle.getSerializable("Events"));
	            Intent newIntent = new Intent(getApplicationContext(), EventListActivity.class);
	            newIntent.putExtras(bundle);
	            startActivity(newIntent);
			}
		});
        
        button_favs.setOnClickListener(new View.OnClickListener() {			
			public void onClick(View v) {
				Bundle bundle = new Bundle();
				Events events = (Events)_bundle.getSerializable("Events");
	            bundle.putSerializable("Favourites", events);
	            Intent newIntent = new Intent(getApplicationContext(), FavouritesActivity.class);
	            newIntent.putExtras(bundle);
	            startActivity(newIntent);			
			}
		});
    }
}